package com.blt.govdata.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.IService;
import com.blt.govdata.controller.base.BaseController;
import com.blt.govdata.core.annotation.Loggable;
import com.blt.govdata.model.vo.TProjectVo;
import com.blt.govdata.service.ITProjectService;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 项目前端控制器
 * </p>
 * @author AustinGJ123
 * @since 2018-03-26
 */
@RestController
@RequestMapping("/tProject")
//todo 将所有的XXX修改为真实值
public class TProjectController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ITProjectService service;


    /**
     * 查询项目
     */
    @RequestMapping(value = "/showProject")
    public Map<String, Object> showProject(@RequestParam Map<String, Object> params) {
        logger.info("查询项目");
        params.put("userId",this.userid);
        if(StringUtils.containsAny(this.username,"admin","super")) params.remove("userId");
        return ImmutableMap.of("status", "true", "data", this.service.showProject(params));
    }

    /**
     * 项目基本情况
     */
    @RequestMapping(value = "/selectProjectBasicInfoPage")
    public Map<String, Object> selectProjectBasicInfoPage(@RequestParam Map<String, Object> params, Page<TProjectVo> page) {
        params.put("userId",this.userid);
        if(StringUtils.containsAny(this.username,"admin","super")) params.remove("userId");
        if (null == params.get("year")) params.put("year", Calendar.getInstance().get(Calendar.YEAR));
        Page<TProjectVo> result = this.service.selectProjectVoPage(page, params);
        logger.info("分页查询项目");
        return ImmutableMap.of("status", "true", "data", result);
    }


    /**
     * 根据Id查询项目基本情况
     */
    @RequestMapping(value = "/selectProjectBasicInfoById", params = {"id"})

    public Map<String, Object> selectProjectBasicInfoById(Integer id, Integer year) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("year", null == year ? Calendar.getInstance().get(Calendar.YEAR) : year);
        params.put("id", id);
        TProjectVo result = this.service.selectProjectBasicInfoById(params);
        logger.info("ID查询项目");
        return ImmutableMap.of("status", "true", "data", result);
    }

    /**
     * 编辑项目基本情况
     */
    @RequestMapping(value = "/editProjectBasicInfo")

    public Map<String, Object> editProjectBasicInfo(TProjectVo tProjectVo) {
        tProjectVo.setGeometry(null);
        boolean result = this.service.editProjectBasicInfo(tProjectVo);
        logger.info("编辑项目基本情况");
        return ImmutableMap.of("status", "true", "data", result);
    }

    /**
     * 分页查询项目几何属性
     * */
    @RequestMapping(value = "/selectGeometryPage")

    public Map<String, Object> selectGeometryPage(@RequestParam Map<String,Object> params,Page page) {
        Page<Map<String,Object>> result = this.service.selectGeometryPage(params,page);
        logger.info("编辑项目基本情况");
        return ImmutableMap.of("status", "true", "data", result);
    }



    /**
     * 查询用户的按钮权限
     * */
    @RequestMapping(value = "/selectUserBtns")

    public Map<String, Object> selectUserBtns() {
        Integer userId = this.userid;
        return ImmutableMap.of("status", "true", "data", this.service.selectUserBtns(userId));
    }







}
